<template>
  <div class="login-container" id="particles" style="background:url(./static/img/login_bg.png) center;">
    <img src="../../assets/images/login_top.png" alt="" class=" login_topimg" />
    <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px" class="card-box login-form">
      <el-form-item prop="username">
        <span class="svg-container svg-container_login">
          <i class="fa fa-user" aria-hidden="true"></i>
        </span>
        <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="请输入用户名" />
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container">
          <i class="fa fa-unlock-alt fa-lg" aria-hidden="true"></i>
        </span>
        <el-input name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on" placeholder="请输入登录密码"></el-input>
      </el-form-item>
     <el-form-item>
        <div id="mpanel"></div>
        <!--&lt;!&ndash;验证插件&ndash;&gt;-->
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width:100%;background: #fff;border-color: #fff;color: #2ca3fb" :loading="loading" @click.native.prevent="handleLogin">
          登录
        </el-button>
      </el-form-item>
    </el-form>
    <div class="bashEditor">
      <p class="p_1">中加生命树项目组</p>
      <p class="p_2">技术支持：上海臻鼎健康科技有限公司</p>
    </div>
  </div>
</template>

<script>
import { isvalidUsername } from "@/utils/validate";
import { setToken } from "@/utils/auth";
import "@/assets/js/verify.js";
import "@/assets/css/verify.css";
export default {
  name: "login",
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入正确的用户名"));
      } else {
        callback();
      }
    };
    const validatePass = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("密码不能小于6位"));
      } else {
        callback();
      }
    };
    return {
      loginForm: {
        username: "",
        password: ""
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入用户名" },
          { validator: validateUsername, trigger: "blur" }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入登录密码" },
          { validator: validatePass, trigger: "blur" }
        ]
      },
      loading: false,
      slideVerify: false //滑动验证判断
    };
  },
  methods: {
    handleLogin() {
      var that = this;
      that.$refs.loginForm.validate(valid => {
        if (valid) {
         if (!that.slideVerify) {
           that.$message({
             message: "请移动滑块验证",
             type: "error"
           });
           return false;
         }

          var crypto = require("crypto");
          var md5 = crypto.createHash("md5");
          md5.update(that.loginForm.password);
          var str = md5.digest("hex");
          that.loginForm.password = str.toUpperCase(); //32位大写

          that.loading = true;
          that.$store
            .dispatch("Login", that.loginForm)
            .then(() => {
              //相应action LOgin的函数执行
              that.loading = false;
              that.$router.push({ path: "/home/index" });
              that.$message({
                message: "登录成功"
              });
            })
            .catch(() => {
              that.loading = false;
              that.$router.push({ path: "/home/index" });
              that.$message({
                message: "登录成功"
              });
              that.loading = false;
            });
        } else {
          return false;
        }
      });
    }
  },
  mounted: function() {
    var that = this;
    //		$(document).ready(function() {
    //			$('#particles').particleground({
    //				dotColor: '#58677b',
    //				lineColor: '#58677b'
    //			});
    //		});
   $("#mpanel").slideVerify({
     type: 1, //类型
     vOffset: 1, //误差量，根据需求自行调整
     barSize: {
       width: "100%",
       height: "40px"
     },
     success: function() {
       that.slideVerify = true;
     },
     error: function() {
       that.slideVerify = false;
       that.$message({
         message: "请重新移动滑块验证",
         type: "error"
       });
     }
   });
//    (function(window) {
//      var theUA = window.navigator.userAgent.toLowerCase();
//      if (
//              (theUA.match(/msie\s\d+/) && theUA.match(/msie\s\d+/)[0]) ||
//              (theUA.match(/trident\s?\d+/) && theUA.match(/trident\s?\d+/)[0])
//      ) {
//        var ieVersion =
//                theUA.match(/msie\s\d+/)[0].match(/\d+/)[0] ||
//                theUA.match(/trident\s?\d+/)[0];
//        if (ieVersion <= 9) {
//          var str =
//                  "你的浏览器版本太low了,已经和时代脱轨了,请使用ie10以上浏览器 :(";
//          var str2 =
//                  "推荐使用谷歌," +
//                  "'火狐," +
//                  "其他双核极速模式";
//          document.writeln(
//                  "<pre style='text-align:center;color:#fff;background-color:#0cc; height:100%;border:0;position:fixed;top:0;left:0;width:100%;z-index:1234'>" +
//                  "<h2 style='padding-top:200px;margin:0'><strong>" +
//                  str +
//                  "<br/></strong></h2><h2>" +
//                  str2 +
//                  "</h2><h2 style='margin:0'><strong>如果你的使用的是双核浏览器,请切换到极速模式访问<br/></strong></h2></pre>"
//          );
//          document.execCommand("Stop");
//        }
//      }
//    })(window);
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
@import "src/styles/mixin.scss";
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  @include relative;
  height: 100vh;
  overflow: hidden;
  /*background-color: $bg;*/

  background-size: 100% 100%;
  input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
    -webkit-text-fill-color: #fff !important;
  }
  input {
    background: transparent;
    background: none;
    border: 0px;
    -webkit-appearance: none;
    border-radius: 0px;
    padding: 12px 5px 12px 15px;
    color: $light_gray;
  }
  ::-webkit-input-placeholder { /* WebKit, Blink, Edge */
    color:    rgba(254,255,255,0.8);
  }
  :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    color:   rgba(254,255,255,0.8);
  }
  ::-moz-placeholder { /* Mozilla Firefox 19+ */
    color:    rgba(254,255,255,0.8);
  }
  :-ms-input-placeholder { /* Internet Explorer 10-11 */
    color:    rgba(254,255,255,0.8);
  }
  .el-input {
    display: inline-block;
    width: 85%;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
  }
  .svg-container {
    padding: 2px 5px 6px 15px;
    color:rgba(254,255,255,0.8);
    vertical-align: middle;
    width: 30px;
    display: inline-block;
    &_login {
      font-size: 20px;
    }
  }
  .title {
    font-size: 26px;
    font-weight: 400;
    color: $light_gray;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }
  .login-form {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 400px;
    padding: 35px 35px 15px 35px;
    margin: 25vh auto;
  }
  .el-form-item {
    border: 1px solid #fff;
    background: none;
    border-radius: 5px;
    color: #454545;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
  }
  .thirdparty-button {
    position: absolute;
    right: 35px;
    bottom: 28px;
  }
  .login_topimg {
    margin: 15vh auto;
    display: block;
    max-width: 100%;
    height: auto;
  }
  .bashEditor{
    position: absolute;
    width:100%;
    right: 0;
    left: 0;
    bottom: 30px;
    text-align: center;
    font-size: 14px;
    color: #EEEEEE;
    .p_1{
      padding-bottom: 15px;
    }
  }
}
</style>
